package com.dt76.smallloanbackenduser.controller.lhuaw;

import com.dt76.smallloanbackenduser.remote.lhuaw.TextMessagetest;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/lhuaw")
public class TextMessageController {
    @Autowired
    private TextMessagetest textMessagetest;

@RequestMapping("/getAllText")
public String getAllText(Model model){
    model.addAttribute("TextList",textMessagetest.getAllText());
    System.out.println("调用成功");
    System.out.println(textMessagetest.getAllText());
    return "pages/lhuaw/TextMessage";
}
@RequestMapping("/qryConditionPageAllText")
public String qryConditionPageAllText(Model model, Integer currentPageNo,
                                  @RequestParam(value ="tPublisher",required = false)String tPublisher
                                  ){
   if (currentPageNo <= 0) {
        currentPageNo = 1;
   }
    String paramtPublisher= "";
    if(tPublisher != null && ! tPublisher.equals("")){
        paramtPublisher ="%"+tPublisher+"%";
    }
    Page page = textMessagetest.qryConditionPageAllText(currentPageNo,paramtPublisher);
    model.addAttribute("qryTextList",page.getRows());
    model.addAttribute("page",page);
    model.addAttribute("tPublisher",tPublisher);
    System.out.println(page.getRows());
    return "pages/lhuaw/TextMessage";
}
    @RequestMapping("/deleteText/{tId}")
    @ResponseBody
    public Result deleteText(@PathVariable String tId){
        return textMessagetest.deleteText(Integer.parseInt(tId));
    }

}
